/*
 * FNISVGEditor - JavaScript - based editor for SVG graphics 
 * Copyright (C) 2008 - 2009 Antti Leppä / Foyt
 * http://www.foyt.fi
 * 
 * License: 
 * 
 * Licensed under GNU Lesser General Public License Version 2.1 or later (the "LGPL") 
 * http://www.gnu.org/licenses/lgpl.html
 */

FNISVGEditorUndoPlugin = Class.create(FNISVGEditorPlugin, {
  initialize : function($super, editorInstance, pluginURL) {
    $super(editorInstance, pluginURL);
    
    this._undoButton = new FNIPushButton( {});
    this._undoButton.setImage(this.getPluginURL() + "/gfx/icons/22x22/actions/edit-undo.png");
    this._undoButton.addListener('buttonClick', this, this._onUndoButtonClick);
    this._undoButton.setDisabled(true);
    this._undoButton.setTooltip(SVGLocale.getText("undoPlugin_undoButtonTooltip"));
    editorInstance.registerToolbarItem('undo', this._undoButton);
    
    this._redoButton = new FNIPushButton( {});
    this._redoButton.setImage(this.getPluginURL() + "/gfx/icons/22x22/actions/edit-redo.png");
    this._redoButton.addListener('buttonClick', this, this._onRedoButtonClick);
    this._redoButton.setDisabled(true);
    this._redoButton.setTooltip(SVGLocale.getText("undoPlugin_redoButtonTooltip"));
    editorInstance.registerToolbarItem('redo', this._redoButton);
    
    editorInstance.getUndoManager().addListener("statusChanged", this, this._onUndoContorllerStatusChanged);
  },
  getName : function() {
    return "undo";
  },
  _onUndoButtonClick: function (event) {
    this.getEditorInstance().getUndoManager().undo();
  },
  _onRedoButtonClick: function (event) {
    this.getEditorInstance().getUndoManager().redo();
  },
  _onUndoContorllerStatusChanged: function (event) {
    this._undoButton.setDisabled(event.hasUndoableEvents == false);  
    this._redoButton.setDisabled(event.hasRedoableEvents == false);
  }
});

document.fire("svgEditorPluginLoaded:undo", {
  pluginClass :FNISVGEditorUndoPlugin
});
